package com.chenfan.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenfan.process.common.utils.QueryWrapperUtils;
import com.chenfan.process.entity.po.ProcessNodeNotifyConfig;
import com.chenfan.process.enums.ApprovalMessageTypeEnum;
import com.chenfan.process.repository.ProcessNodeNotifyConfigRepository;
import com.chenfan.process.service.ProcessNodeNotifyConfigService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProcessNodeNotifyConfigServiceImpl extends ServiceImpl<ProcessNodeNotifyConfigRepository, ProcessNodeNotifyConfig> implements ProcessNodeNotifyConfigService {
    @Override
    public List<ProcessNodeNotifyConfig> listWithProcessId(Long processId, ApprovalMessageTypeEnum messageType) {
        QueryWrapper<ProcessNodeNotifyConfig> queryWrapper = QueryWrapperUtils.newQueryWrapper();
        queryWrapper.eq(ProcessNodeNotifyConfig.Constants.PROCESS_ID, processId);
        queryWrapper.and(wrapper -> wrapper.eq(ProcessNodeNotifyConfig.Constants.MESSAGE_TYPE, messageType.getType())
                .or()
                .eq(ProcessNodeNotifyConfig.Constants.MESSAGE_TYPE, ApprovalMessageTypeEnum.BUSINESS));
        return this.list(queryWrapper);
    }
}
